﻿@model Host.Models.RegModel
           
@{
    ViewBag.Title = "Regulation 28 Revised";
}

<h2>Regulation 28 Revised</h2>
<style type="text/css">
    .highLight{ background-color:Orange;  font-weight:bold;}
   
    .validated{}
    .errorFormula{}
</style>

@using (Html.BeginForm())
{

<table style="width:90%;">
    <thead class="ui-grid-header ui-widget-header ui-corner-top ui-state-default" style="height:30px;">
        <tr>
            <td>
                Asset Class/Instrument
                </td>
                <td>
                    Old Regulation 28
                </td>
                <td>
                    New Regulation 28
                   </td>
                    <td>
                        Input Values
                    </td>
        </tr>
    </thead>
    <tbody class="ui-grid-content ui-widget-content">
    <tr class="highLight">
        <td>Cash</td>
        <td>100%</td>
        <td>100%</td>
        <td><label id="cashPerIssuer"></label> <label id="ForeignBank"></label></td>
    </tr>
    <tr>
        <td>Per Issuer</td>
        <td>20%</td>
        <td>25%</td>
        <td>
         @Html.TextBoxFor(m => m.PerIssuer, new { @id = "txtPerIssuer", onblur = "AddCash()" })
        </td>
    </tr>
    <tr>
        <td>Foreign bank</td>
        <td></td>
        <td>5%</td>
        <td>
            @Html.TextBoxFor(m => m.ForeignBank, new { @id = "txtForeignBank", onblur = "AddCash()"  })
        </td>
    </tr>
    <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalCash, new { @id = "txtTotalCash" , onblur = "AddCash()" })
        </td>
    </tr>
    <tr class="highLight">
        <td>Debt Instruments (Bonds)</td>
        <td>100%</td>
        <td>100%</td>
        <td><label id="TotalDebtInstuments"/></td>
    </tr>
    <tr>
        <td>
            Guaranteed by the Republic of SA</td>
            <td>100%</td>
            <td>100%</td>
            <td>
            @Html.TextBoxFor(m => m.GbyRSA, new { @id = "txtGbyRSA" })
            </td>
    </tr>
    <tr>
        <td>
            Otherwise (banks etc)</td>
            <td>100%</td>
            <td></td>
            <td>
            @Html.TextBoxFor(m => m.OtherBanks, new { @id = "txtOtherBanks" })
            </td>
    </tr>
    <tr>
        <td>
            (20% per issuer)</td>
        <td>75%</td>
        <td></td>
        <td>
            @Html.TextBoxFor(m => m.PerIssuer20, new { @id = "txt20PerIssuer" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer marker cap > R20bn
        </td>
        <td>
            
        </td>
        <td>25%</td>
        <td>
        @Html.TextBoxFor(m => m.ListedIssuerMarkerCap20Bn, new { @id = "txtListedIssuerMarkerCap20Bn" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer marker cap > R2bn & < R20bn
        </td>
        <td></td>
        <td>15%</td>
        <td>
          @Html.TextBoxFor(m => m.ListedIssuerMarkerCap2bnTo20bn, new { @id = "txtListedIssuerMarkerCap2bnTo20bn" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer maker cap < R2bn
        </td>
        <td>
        
        </td>
        <td>
        10%
        </td>
        <td>
        @Html.TextBoxFor(m => m.ListedIssuerMarkerCapLess2bn, new { @id = "txtListedIssuerMarkerCapLess2bn" })

        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Not listed on an exchange</td>
            <td></td>
            <td>5%</td>
            <td>
            @Html.TextBoxFor(m => m.ListedNotOnexchange, new { @id = "txtListedNotOnexchange" })
            </td>
    </tr>
    <tr>
        <td>
            Guaranteed by foreign country</td>
            <td>10%</td>
            <td>10%</td>
            <td>
            @Html.TextBoxFor(m => m.GuarenteedByForeignCountry, new { @id = "txtGuarenteedByForeignCountry" })
            </td>
    </tr>
    <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalDebtInstuments, new { @id = "txtTotalDebtInstuments" })
        </td>
    </tr>
    <tr class="highLight">
    <td>
        Equities
    </td>
    <td>75%
    </td>
    <td>75%</td>
    <td><label id="TotalEquityExchange"/></td>
    </tr>
    <tr>
        <td>
            Listed & issuer marker cap > R20bn</td>
            <td>
                15%
            </td>
            <td>15%
            </td>
            <td>
            @Html.TextBoxFor(m => m.EquatyListedIssuerMarkerCapMore2bn, new { @id = "txtEquatyListedIssuerMarkerCapMore2bn" })
            </td>
    </tr>
    <tr>
        <td>
            Listed & issuer marker cap > R2bn & < R20bn
        </td>
        <td>
            15%
        </td>
        <td>
        15%
        </td>
        <td>
        @Html.TextBoxFor(m => m.EquatyListedMarkerCapBetween2bnTo20bn, new { @id = "txtEquatyListedMarkerCapBetween2bnTo20bn" })

        </td>
    </tr>
    <tr>
        <td>
        Listed & issuer maker cap < R2bn
        </td>
        <td>
            10%
        </td>
        <td>
            5%
        </td>
        <td>
        @Html.TextBoxFor(m => m.EquatyListedIssuerMarkerCapBelow2bn, new { @id = "txtEquatyListedIssuerMarkerCapBelow2bn" })
        </td>
    </tr>
    <tr>
        <td>
            Not listed on an exchange
        </td>
        <td>
            5%
        </td>
        <td>2.5%</td>
        <td>
        @Html.TextBoxFor(m => m.EquatyExchange, new { @id = "txtEquatyExchange" })
        </td>
    </tr>
    <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalEquityExchange, new { @id = "txtTotalEquityExchange" })
        </td>
    </tr>
    <tr class="highLight">
        <td>
            Immovable Property</td>
            <td>
                25%
            </td>
            <td>
                25%
            </td>
            <td><label id="TotalIM"/></td>
    </tr>
    <tr>
        <td>
        Listed Property
        </td>
        <td>
            
        </td>
        <td>
            25%
        </td>
        <td>
        @Html.TextBoxFor(m => m.IMListedProperty, new { @id = "txtIMListedProperty" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer marker cap > R10bn</td>
            <td></td>
            <td>25%</td>
            <td>
            @Html.TextBoxFor(m => m.IMListedMarkerMore10bn, new { @id = "txtIMListedMarkerMore10bn" })
            </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer marker cap > R3bn & < R10bn
        </td>
        <td>
            
        </td>
        <td>10%</td>
        <td>
        @Html.TextBoxFor(m => m.IMListedMarkerCapBetween3bnAnd10Bn, new { @id = "txtIMListedMarkerCapBetween3bnAnd10Bn" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
            Listed & issuer maker cap < R3bn</td>
            <td></td>
            <td>5%</td>
            <td>
                @Html.TextBoxFor(m => m.IMListedMarkerCapLess3bn, new { @id = "txtIMListedMarkerCapLess3bn" })
            </td>
    </tr>
    <tr>
        <td>Unlisted / direct property</td>
        <td></td>
        <td>15%</td>
        <td>
            @Html.TextBoxFor(m => m.IMDirectPropertyUnlisted, new { @id = "txtIMDirectPropertyUnlisted" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">Per Issuer</td>
        <td></td>
        <td>15%</td>
        <td>
        @Html.TextBoxFor(m => m.IMUnlistedPerIssuer, new { @id = "txtIMUnlistedPerIssuer" })
        </td>
    </tr>
    <tr>
        <td>Direct & Listed property</td>
        <td>25%</td>
        <td></td>
        <td>@Html.TextBoxFor(m => m.IMDirectProperty, new { @id = "txtIMDirectProperty" })
        </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
        Per Single Property
        </td>
        <td>5%</td>
        <td></td>
        <td>
            @Html.TextBoxFor(m => m.IMSingleProperty, new { @id = "txtIMSingleProperty" })
        </td>
    </tr>
    <tr>
        <td>
            Foreign property</td>
            <td>
                10%
            </td>
            <td></td>
            <td>
            @Html.TextBoxFor(m => m.IMFoerienProperty, new { @id = "txtIMFoerienProperty" })
            </td>
    </tr>
    <tr>
        <td style="padding-left:10px;">
                Per single property
        </td>
        <td>
            5%
        </td>
        <td>
            
        </td>
        <td>
        @Html.TextBoxFor(m => m.IMForeignPropSingleProp, new { @id = "txtIMForeignPropSingleProp" })
        </td>
     </tr>
    <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td><input type="text" id="txtTotalIM" /></td>
    </tr>
    <tr class="highLight">
            <td>
            Commodities
            </td>
            <td>
                10%
            </td>
            <td>10%</td>
            <td><label id="TotalCommodities"/></td>
     </tr>
     <tr>
        <td>Gold</td>
        <td>10% [Krugerrands]</td>
        <td>10%</td>
        <td>
        @Html.TextBoxFor(m => m.CommKruger, new { @id = "txtCommKruger" })
        </td>
     </tr>
     <tr>
        <td>Other</td>
        <td></td>
        <td>5%</td>
        <td>
        @Html.TextBoxFor(m => m.CommOther, new { @id = "txtCommOther" })
        </td>
     </tr>
     <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalCommodities, new { @id = "txtTotalCommodities" })
        </td>
    </tr>
     <tr class="highLight">
        <td>
            Investments in a participating employer</td>
            <td></td>
            <td></td>
            <td><label id="TotalInvestmentsEmployer"/></td>
     </tr>
     <tr>
        <td>
            In terms of section 19(4) of the Pension Funds Act</td>
            <td>5%</td>
            <td>5%</td>
            <td>
                @Html.TextBoxFor(m => m.InvestTermsSection, new { @id = "txtInvestTermsSection" })
            </td>
     </tr>
     <tr>
        <td>
            With exemption from section 19(4)</td>
            <td>10%</td>
            <td>10%</td>
            <td>
            @Html.TextBoxFor(m => m.InvestExemption, new { @id = "txtInvestExemption" })
            </td>
     </tr>
     <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalInvestmentsEmployer, new { @id = "txtTotalInvestmentsEmployer" })
        </td>
    </tr>
     <tr class="highLight">
        <td>
            Hedge Funds, Private Equity and other</td>
            <td>N/A</td>
            <td>15%</td>
            <td><label id="TotalHedgeOtherAssets"/></td>
     </tr>
     <tr>
        <td>
            Hedge funds</td>
            <td></td>
            <td>10%</td>
            <td>
            @Html.TextBoxFor(m => m.HedgeFunds, new { @id = "txtHedgeFunds" })
            </td>
     </tr>
     <tr>
        <td style="padding-left:10px;">Per Fund of Hedge funds</td>
        <td></td>
        <td>5%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgePerFund, new { @id = "txtHedgePerFund" })
        </td>
     </tr>
     <tr>
        <td style="padding-left:10px;">
        Per hedge fund
        </td>
        <td></td>
        <td>2.50%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgePerHedgeFund, new { @id = "txtHedgePerHedgeFund" })
           
        </td>
     </tr>
     <tr>
        <td style="padding-left:10px;">
            Private equity
        </td>
        <td>
            
        </td>
        <td>10%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgePrivateEquity, new { @id = "txtHedgePrivateEquity" })
        </td>
     </tr>
     <tr>
        <td>Per Funds of private equity</td>
        <td></td>
        <td>5%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgePerFundPrivateEquity, new { @id = "txtHedgePerFundPrivateEquity" })
        </td>
     </tr>
     <tr>
        <td>Per private equity fund</td>
        <td></td>
        <td>2.50%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgePerPrivateEquityFund, new { @id = "txtHedgePerPrivateEquityFund" })
        </td>
     </tr>
     <tr>
        <td style="padding-left:10px;">Other assets</td>
        <td></td>
        <td>2.50%</td>
        <td>
        @Html.TextBoxFor(m => m.HedgeOtherAssets, new { @id = "txtHedgeOtherAssets" })
        </td>
     </tr>
     <tr>
        <td colspan="2"></td>
        <td style="text-align:right;"><b>Total:</b></td>
        <td>
        @Html.TextBoxFor(m => m.TotalInvestmentsEmployer, new { @id = "txtTotalHedgeOtherAssets" })
        </td>
    </tr>
     <tr class="highLight">
        <td>Other assets</td>
        <td>2.50%</td>
        <td></td>
        <td></td>
     </tr>
     
    </tbody>
    <tfoot class="ui-grid-footer ui-widget-header ui-corner-bottom" style="height:30px;">
        <tr>
            <td colspan="4">
            Totals:
            </td>
        </tr>
    </tfoot>
</table>
<p></p>
 <input type="submit" value="Generate" />
}

<script id="validation" type="text/javascript">
    function Validate(i, control){
    //Check that Cash = 100%
        //var i = $( "#txtPerIssuer" ).val();
        if ( isNaN( i ) ){
            // alert( "Not a number" );
            //error
            control.css( 'background-color', 'red' );
        } else
        {
            //    alert( "Is a Number" );
            control.css( 'background-color', 'white' );
        }
    }
    $( function ()
    {

        $( ":input" ).keydown( function ()
        {
            if ( isNaN( $( this ).val() ) ) { $( this ).addClass( 'error' ); ; $( this ).tooltip().show(); } else { $( this ).removeClass( 'error' );  $( this ).tooltip().hide(); }
        } );

        $( ":input" ).attr( 'title', 'Only numbers allowed' );

        $( "[title]" ).tooltip();

        $( ":input" ).focus( function () { $( this ).tooltip().hide(); } );
    } );

    $(function () {

        /* Check the CASH section of the form */
        //$("#txtForeignBank").blur(function () { AddCash(); });
       // $("#txtPerIssuer").blur(function () { AddCash(); });

        /* Check the DEBT INSTRUCTION section of the form */
        $("#txtGbyRSA").blur(function () { AddDebtInstruction(); });
        $("#txtOtherBanks").blur(function () { AddDebtInstruction(); });
        $("#txt20PerIssuer").blur(function () { AddDebtInstruction(); });
        $("#txtListedIssuerMarkerCap20Bn").blur(function () { AddDebtInstruction(); });
        $("#txtListedIssuerMarkerCap2bnTo20bn").blur(function () { AddDebtInstruction(); });
        $("#txtListedIssuerMarkerCapLess2bn").blur(function () { AddDebtInstruction(); });
        $("#txtListedNotOnexchange").blur(function () { AddDebtInstruction(); });
        $("#txtGuarenteedByForeignCountry").blur(function () { AddDebtInstruction(); });
        $("#txtTotalDebtInstuments").blur(function () { AddDebtInstruction(); });

        /* Check the EQITIES section of the form */
        $("#txtEquatyListedIssuerMarkerCapMore2bn").blur(function () { AddEquities(); });
        $("#txtEquatyListedMarkerCapBetween2bnTo20bn").blur(function () { AddEquities(); });
        $("#txtEquatyListedIssuerMarkerCapBelow2bn").blur(function () { AddEquities(); });
        $("#txtEquatyExchange").blur(function () { AddEquities(); });
        $("#txtTotalEquityExchange").blur(function () { AddEquities(); });

        /* Check the IMMOVABLE PROPERTY section of the form */
        $("#txtIMListedProperty").blur(function () { AdddIM(); });
        $("#txtIMListedMarkerMore10bn").blur(function () { AdddIM(); });
        $("#txtIMListedMarkerCapBetween3bnAnd10Bn").blur(function () { AdddIM(); });
        $("#txtIMListedMarkerCapLess3bn").blur(function () { AdddIM(); });
        $("#txtIMDirectPropertyUnlisted").blur(function () { AdddIM(); });
        $("#txtIMUnlistedPerIssuer").blur(function () { AdddIM(); });
        $("#txtIMDirectProperty").blur(function () { AdddIM(); });
        $("#txtIMSingleProperty").blur(function () { AdddIM(); });
        $("#txtIMFoerienProperty").blur(function () { AdddIM(); });
        $("#txtIMForeignPropSingleProp").blur(function () { AdddIM(); });
        $("#txtTotalIM").blur(function () { AdddIM(); });

        /* Check the COMMODITIES Section of the form */
        $("#txtCommKruger").blur(function () { AddCommodities(); });
        $("#txtCommOther").blur(function () { AddCommodities(); });
        $("#txtTotalCommodities").blur(function () { AddCommodities(); });

        /* Check the INVESTMENTS OF EMPLOYER section of the form */
        $("#txtInvestTermsSection").blur(function () { AddInvestEmployer(); });
        $("#txtInvestExemption").blur(function () { AddInvestEmployer(); });
        $("#txtTotalInvestmentsEmployer").blur(function () { AddInvestEmployer(); });


        /* Check HEDGE FUNDS section of the form*/
        $("#txtHedgeFunds").blur(function () { AddHedge(); });
        $("#txtHedgePerFund").blur(function () { AddHedge(); });
        $("#txtHedgePerHedgeFund").blur(function () { AddHedge(); });
        $("#txtHedgePrivateEquity").blur(function () { AddHedge(); });
        $("#txtHedgePerFundPrivateEquity").blur(function () { AddHedge(); });
        $("#txtHedgePerPrivateEquityFund").blur(function () { AddHedge(); });
        $("#txtHedgeOtherAssets").blur(function () { AddHedge(); });
        
    });
    /* CASH Section */
    function AddCash() {
        var a = parseInt($("#txtForeignBank").val());
        var b = parseInt($("#txtPerIssuer").val());
        var va = a * 4;

        var total = parseInt($("#txtTotalCash").val());
        var perc25 = total / 4;
        if (Math.round((b / total) * 100) != 25) {
            $("#cashPerIssuer").text('Per Issuer: ' + Math.round((b / total) * 100) + " %");
        }

        if (Math.round((a / total) * 100) != 5) {
            $("#ForeignBank").text('Foreign Bank: ' + Math.round((a / total) * 100) + ' %');
        }
        //$("#cashPerIssuer").text(Math.round((b / total) * 100));
       // $("#ForeignBank").text(Math.round((a / total) * 100));
        

        //$("#cashTotal").text(a+b);
       //00 $('#ForeignBank').currency({ region: 'ZAR', thousands: '', decimal: ',', decimals: 2 });
       // $('#cashPerIssuer').currency({ region: 'ZAR', thousands: '', decimal: ',', decimals: 2 });
       // $('#txtTotalCash').currency({ region: 'ZAR', thousands: '', decimal: ',', decimals: 2   });
    };

    /* DEBT section */
    function AddDebtInstruction() {
        var totalDebtIntruction = parseInt($("#txtTotalDebtInstuments").val());
        var GRSA =  parseInt($("#txtGbyRSA").val());
        var OtherB = parseInt($("#txtOtherBanks").val());
        var PIssuer20 =  parseInt($("#txt20PerIssuer").val());
        var ListedIssuerMCap20Bn = parseInt($("#txtListedIssuerMarkerCap20Bn").val());
        var LIMC2To20Bn =  parseInt($("#txtListedIssuerMarkerCap2bnTo20bn").val());
        var LIMCL20bn =  parseInt($("#txtListedIssuerMarkerCapLess2bn").val());
        var LNOE =  parseInt($("#txtListedNotOnexchange").val());
        var GBFC =  parseInt($("#txtGuarenteedByForeignCountry").val());

        $("#TotalDebtInstuments").text(GRSA + OtherB + PIssuer20 + ListedIssuerMCap20Bn + LIMC2To20Bn + LIMCL20bn + LNOE + GBFC);
       

    }

    /* EQUITIES Section */
    function AddEquities(){
        var totalEquities = $("#txtTotalEquityExchange").val();

        var ELIMCM2Bn =  parseInt($("#txtEquatyListedIssuerMarkerCapMore2bn").val());
        var ELMCB2bn20Bn =  parseInt($("#txtEquatyListedMarkerCapBetween2bnTo20bn").val());
        var ELIMBW2bn =  parseInt($("#txtEquatyListedIssuerMarkerCapBelow2bn").val());
        var EE = parseInt($("#txtEquatyExchange").val());
        $("#TotalEquityExchange").text(ELIMCM2Bn + ELMCB2bn20Bn + ELIMBW2bn + EE);

    }

    /* IMMOVABLE PROPERTY section */
    function AdddIM(){
        var totalIM = $("#txtTotalIM").val();

        var IMLP =  parseInt($("#txtIMListedProperty").val());
        var IMLMM10Bn =  parseInt($("#txtIMListedMarkerMore10bn").val());
        var IMLMCBW2bn10bn = parseInt($("#txtIMListedMarkerCapBetween3bnAnd10Bn").val());
        var IMLCL3bn = parseInt($("#txtIMListedMarkerCapLess3bn").val());
        var IMDPL =  parseInt($("#txtIMDirectPropertyUnlisted").val());
        var IMULPI = parseInt($("#txtIMUnlistedPerIssuer").val());
        var IMDP = parseInt($("#txtIMDirectProperty").val());
        var IMSP = parseInt($("#txtIMSingleProperty").val());
        var IMFP = parseInt($("#txtIMFoerienProperty").val());
        var IMFPSP = parseInt($("#txtIMForeignPropSingleProp").val());

        $("#TotalIM").text(IMLP + IMLMM10Bn + IMLMCBW2bn10bn + IMLCL3bn + IMDPL + IMULPI + IMDP + IMSP + IMFP + IMFPSP);
    }

    /* COMMODITIES Section */
    function AddCommodities() {
        var totalCommidities = $("#txtTotalCommodities").val();

        var CK = parseInt( $("#txtCommKruger").val());
        var CO = parseInt( $("#txtCommOther").val());

        $("#TotalCommodities").text(CK + CO);
    }

    /* INVESTMENTS OF Employer section */
    function AddInvestEmployer() {
        var totalInvestEmployer = $("#txtTotalInvestmentsEmployer").val();

        var ITS = parseInt( $("#txtInvestTermsSection").val());
        var IE = parseInt($("#txtInvestExemption").val());

        $("#TotalInvestmentsEmployer").text(ITS + IE);
    }

    /* HEDGE FUNDS section */
    function AddHedge() {
        var totalHedge =  parseInt($("#txtTotalHedgeOtherAssets").val());

        var HF = parseInt($("#txtHedgeFunds").val());
        var HPF = parseInt($("#txtHedgePerFund").val());
        var HPHF = parseInt($("#txtHedgePerHedgeFund").val());
        var HPE = parseInt($("#txtHedgePrivateEquity").val());
        var HPFPE = parseInt($("#txtHedgePerFundPrivateEquity").val());
        var HPPEF = parseInt($("#txtHedgePerPrivateEquityFund").val());
        var HOA = parseInt($("#txtHedgeOtherAssets").val());

        ("#TotalHedgeOtherAssets").text(HF + HPF + HPHF + HPE + HPFPE + HPPEF + HOA);

        alert(HF);
    }
</script>